TimedEvent v1.0 (copy C) - provides a time-elapsed event.
By Matthew Peterson, matthew@pinoko.berkeley.edu
[Description]
2-29-2000
Currently, there is no simple timer to be used in Qscript. It is often useful to have an event executed at some set time in the future. This behavior provides the simplest interface for this. I have provided a few different copies of this behavior if you want more than one timer. Don't use the same copy twice in the same sprite track, the variables will overlap.
To use this behavior. Place it in one of your sprites. Setting and starting the timer is all done through the following global variables:
Global Variables:
1) CtimerTicks -- Set this to the number of ticks to elapse before the timer executes your custom event as set in the parameters. A tick is 1/60th of a second. So the following will set the timer to fire in 1 second: CtimerTicks = 60.
This variable is reset to zero after the timer has fired, thus it is necessary to reset the timer each time it is used. You can also check to see if the timer is still running by seeing if this variable is greater than zero or not. So:
IF(CtimerTicks)
//timer is still running.
ENDIF
Once the timer is running, it is not recommended to change this variables value, except under one situation: You can cancel a timer at any time by setting CtimerTicks to zero. This will stop the timer, and the timer's custom event will not be executed.
2) CtimerStart -- Set this to true to start the timer. The timer will begin counting from the next idle event. Once the timer is started, this value will be reset to False.
Revision History:
[Parameters]
Ctimer Alarm Event ID:, MP_CtimerEventID,203
[Idle]
globalvars Ctimerticks Ctimerstart
//Timer A.
//To set the timer, seet Ctimerticks to the number of ticks
//to wait. A tick is 1/60th of a second. So to wait 1 second,
//set Ctimerticks to 60.
//To start the timer, set Ctimerstart to true.
//You need to set these values every time, because they
//get reset by the timer.
//Timing starts from the first idle event after the timer
//is set. The accuracy is determined by the idle rate, and
//the speed of the processor.
//Check to see if the tickcount is bast the CtimerTicks or not
if(CtimerStart)//Did the timer just get activated?
Ctimerticks = Ctimerticks + tickcount
CtimerStart = false //reset the start "button"
elseif(Ctimerticks > 0 and Ctimerticks < tickcount)
Ctimerticks = 0
executeevent($MP_CtimerEventID)//If so, execute the custom event.